package com.rsk.dao.utils;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.stereotype.Component;

@Component
public class BatchDataUitl {
	
	@Autowired
	private NamedParameterJdbcTemplate namedParameterJdbcTemplate;
	
	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	public int batchDataName(String sql, List<?> list){
		//String sql = "INSERT INTO sys_depts(id,dept_code,dept_name) VALUES (:Id,:deptCode,:deptName)";//sql形式
		SqlParameterSource[] beanSources  = SqlParameterSourceUtils.createBatch(list.toArray());
		namedParameterJdbcTemplate.batchUpdate(sql, beanSources);
		return 1;
	}
	
	public int batchDataParam(String sql, List<Object[]> list){
	    //String sql = "INSERT INTO sys_depts (id,dept_code,dept_name) VALUES (?,?,?) ";//sql形式
        jdbcTemplate.batchUpdate(sql, list);
		return 1;
	}
}
